home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * ifaddr.c --
- *
- * Prints the link-level address of an Ethernet or FDDI interface.
- *
- * Usage: ifaddr [name]
- * Where "name" is the interface name used with ifconfig:
- * e.g., et0, ec0, enp0, enp1, ipg0, etc.
- * If "name" not specified, the primary interface is used.
- * Note: fddi addresses are shown in fddi bit order (which are swapped
- * from ether bit order).
- *
- * Compile: cc ifaddr.c -lsun -o ifaddr
- *
- * Must have superuser privilege to execute.
- *
- * Valid for IRIX 3.3 and IRIX 4.0.
- */
-
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <net/raw.h>
- #include <netinet/if_ether.h>
- #include <stdio.h>
- #include <string.h>
-
- extern char *ether_ntoa();
-
- main(int argc, char **argv)
- {
- struct ifreq req;
- struct sockaddr_raw sr;
- int s;
- char *iface;
-
- s = socket(AF_RAW, SOCK_RAW, 0);
- if (s < 0) {
- perror("socket");
- exit(1);
- }
- if (argc < 2) {
- int cc;
-
- bzero(&sr, sizeof(sr));
- sr.sr_family = AF_RAW;
- sr.sr_port = 0;
- if (bind(s, &sr, sizeof sr) < 0) {
- perror("bind");
- exit(1);
- }
- cc = sizeof sr;
- if (getsockname(s, (struct sockaddr *)&sr, &cc) < 0) {
- perror("getsockname");
- exit(1);
- }
- iface = sr.sr_ifname;
- } else {
- iface = argv[1];
- }
-
- bzero(&req, sizeof(req));
- (void) strncpy(req.ifr_name, iface, sizeof req.ifr_name);
-
- if (ioctl(s, SIOCGIFADDR, &req, sizeof(req)) < 0) {
- perror("ioctl");
- exit(1);
- }
- (void) printf("%s = %s\n",
- iface, ether_ntoa(((struct sockaddr_raw *)&req.ifr_addr)->sr_addr));
-
- /*NOTREACHED*/
- exit(0);
- }
-